<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<form action="${ctx}/wechatrobotmedia/save" method="post" role="form" id="form">
					<input type="hidden" name="wechatRobotMedia.id" id="wechatRobotMedia.id" value="${wechatRobotMedia.id!}">
					<input type="hidden" name="flag" id="flag" value="${flag!}">
					<div class="form-group">
						<input type="hidden" type="number" class="form-control" id="wechatRobotMedia.wechat_robot_id" name="wechatRobotMedia.wechat_robot_id" placeholder="自动回复id" value="${wechatRobotMedia.wechat_robot_id!}">
					</div>
					<div class="form-group" id="select">
						<label for="wechatRobotMedia.reply_content_type">回复内容类型</label>
						<select id="wechatRobotMedia.reply_content_type" name="wechatRobotMedia.reply_content_type" class="form-control" value="${wechatRobotMedia.reply_content_type!}" onchange="show_or_hide(this.value)">
							<option value = "0" <#if wechatRobotMedia.reply_content_type??&&wechatRobotMedia.reply_content_type==0>selected="selected"</#if>>文本</option>
							<option value = "1" <#if wechatRobotMedia.reply_content_type??&&wechatRobotMedia.reply_content_type==1>selected="selected"</#if>>图片</option>
							<option value = "2" <#if wechatRobotMedia.reply_content_type??&&wechatRobotMedia.reply_content_type==2>selected="selected"</#if>>音频</option>
							<option value = "3" <#if wechatRobotMedia.reply_content_type??&&wechatRobotMedia.reply_content_type==3>selected="selected"</#if>>视频</option>
							<option hidden value = "4" <#if wechatRobotMedia.reply_content_type??&&wechatRobotMedia.reply_content_type==4>selected="selected"</#if>>音乐</option>
							<option value = "5" <#if wechatRobotMedia.reply_content_type??&&wechatRobotMedia.reply_content_type==5>selected="selected"</#if>>图文</option>
						</select>
					</div>
					<div class="form-group" id="content_text" hidden>
						<label for="wechatRobotMedia.content_text">回复内容</label>
                        <textarea id="wechatRobotMedia.content_text" name="wechatRobotMedia.content_text" class="form-control" rows="5">${wechatRobotMedia.content_text!}</textarea>
					</div>
					<div class="form-group" id="media_id" hidden>
						<label for="wechatRobotMedia.media_id">多媒体素材ID</label>
						<input type="text" class="form-control" id="wechatRobotMedia.media_id" name="wechatRobotMedia.media_id" placeholder="多媒体素材ID" value="${wechatRobotMedia.media_id!}">
					</div>
					<div class="form-group" id="title" hidden>
						<label for="wechatRobotMedia.title">标题</label>
						<input type="text" class="form-control" id="wechatRobotMedia.title" name="wechatRobotMedia.title" placeholder="标题" value="${wechatRobotMedia.title!}">
					</div>
					<div class="form-group" id="description" hidden>
						<label for="wechatRobotMedia.description">描述</label>
						<input type="text" class="form-control" id="wechatRobotMedia.description" name="wechatRobotMedia.description" placeholder="描述" value="${wechatRobotMedia.description!}">
					</div>
					<div class="form-group" id="pic_url" hidden>
						<label for="wechatRobotMedia.pic_url">图片连接</label>
						<input type="text" class="form-control" id="wechatRobotMedia.pic_url" name="wechatRobotMedia.pic_url" placeholder="图片连接" value="${wechatRobotMedia.pic_url!}">
					</div>
					<div class="form-group" id="url" hidden>
						<label for="wechatRobotMedia.url">图文消息链接</label>
						<input type="text" class="form-control" id="wechatRobotMedia.url" name="wechatRobotMedia.url" placeholder="图文消息链接" value="${wechatRobotMedia.url!}">
					</div>
					<div id="music">抱歉！音乐回复暂不支持！</div>
					<button id="savebtn" type="button" class="btn btn-info" onclick="closeAll()">保存</button>
				</form>
			</div>
		</div>
	</div>
</section>

<script src="${ctx}/adminlte/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="${ctx}/adminlte/plugins/jQuery/jquery.form.js"></script>
<script type="text/javascript">
	$(document).ready(function(){

        if($("#flag").val()==1){
            var select = document.getElementById('wechatRobotMedia.reply_content_type')
			select.options[0].setAttribute("hidden",true);
            select.options[1].setAttribute("hidden",true);
            select.options[2].setAttribute("hidden",true);
            select.options[3].setAttribute("hidden",true);
            select.options[4].setAttribute("hidden",true);
            select.options[5].selected=true;
		}

        document.getElementById('wechatRobotMedia.reply_content_type').onchange();
	});

    function closeAll() {
        $("#form").ajaxSubmit(function(e){
            parent.location.reload();
            parent.layer.closeAll();
		});

    }
    function show_or_hide(s) {
        if(s=="0"){
            $("#content_text").show();
            $("#media_id").hide();
            $("#title").hide();
            $("#description").hide();
            $("#pic_url").hide();
            $("#url").hide();
            $("#music").hide();
            $("#savebtn").show();
            clear();
        }else if(s=="1"){
            $("#content_text").hide();
        	$("#media_id").show();
        	$("#title").hide();
        	$("#description").hide();
        	$("#pic_url").hide();
        	$("#url").hide();
            $("#music").hide();
            $("#savebtn").show();
            clear();
        }else if(s=="2"){
            $("#content_text").hide();
            $("#media_id").show();
            $("#title").hide();
            $("#description").hide();
            $("#pic_url").hide();
            $("#url").hide();
            $("#music").hide();
            $("#savebtn").show();
            clear();
        }else if(s=="3"){
            $("#content_text").hide();
            $("#media_id").show();
            $("#title").show();
            $("#description").show();
            $("#pic_url").hide();
            $("#url").hide();
            $("#music").hide();
            $("#savebtn").show();
            clear();
//        }else if(s=="4"){
//            $("#content_text").hide();
//            $("#media_id").hide();
//            $("#title").hide();
//            $("#description").hide();
//            $("#pic_url").hide();
//            $("#url").hide();
//            $("#music").show();
//            $("#savebtn").hide();
//            clear();
        }else if(s=="5"){
            $("#content_text").hide();
            $("#media_id").hide();
            $("#title").show();
            $("#description").show();
            $("#pic_url").show();
            $("#url").show();
            $("#music").hide();
            $("#savebtn").show();
            clear();
        }

        function clear() {
            if(s!="0"){
                document.getElementById('wechatRobotMedia.content_text').value=null;
			}
			if(s!="1"&&s!="2"&&s!="3"){
                document.getElementById('wechatRobotMedia.media_id').value=null;
			}
			if(s!="3"&&s!="5"){
                document.getElementById('wechatRobotMedia.title').value=null;
			}
            if(s!="3"&&s!="5"){
                document.getElementById('wechatRobotMedia.description').value=null;
			}
			if(s!="5"){
                document.getElementById('wechatRobotMedia.pic_url').value=null;
                document.getElementById('wechatRobotMedia.url').value=null;
			}

        }
    }
</script>
